﻿@{ 
    Layout = null;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>

    </title>
    <link href="~/element-ui/element-ui/theme-chalk/index.css" rel="stylesheet" />
    <script src="~/js/vue.js"></script>
    <script src="~/element-ui/element-ui/element.js"></script>
    <script src="~/js/axios.min.js"></script>
</head>
<body>
    <div id="div">
        <span class="demonstration"></span>
        <template>
            <el-table :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
                      height="450"
                      border
                      style="width: 50%">
                <el-table-column prop="staff_CODE"
                                 label="工号"
                                 width="180">
                </el-table-column>
                <el-table-column prop="staff_NAME"
                                 label="姓名"
                                 width="180">
                </el-table-column>
                <el-table-column prop="role.role_Name"
                                 label="角色" width="180">
                </el-table-column>

                <el-table-column fixed="right"
                                 label="操作"
                                 width="120">
                    <template slot-scope="scope">
                        <el-button size="mini"
                                   @@click="handleEdit(scope.$index,scope.row)">编辑</el-button>
                        <!-- 编辑时候的弹出层 -->
                        <el-dialog title="编辑用户"
                                   :visible.sync="dialogFormVisible"
                                   width="500px"
                                   top="200px">
                            <el-form :model="form">
                                <el-form-item label="工号:"
                                              :label-width="formLabelWidth">
                                    <el-input v-model="form.staff_CODE"
                                              auto-complete="off"></el-input>
                                </el-form-item>
                                <el-form-item label="姓名:"
                                              :label-width="formLabelWidth">
                                    <el-input v-model="form.staff_NAME"
                                              auto-complete="off"></el-input>
                                </el-form-item>
                                <el-form-item label="角色:"
                                              :label-width="formLabelWidth">
                                    <el-select v-model="form.role_ID"> <el-option v-for="item in tableData1" :key="item.role_ID" :label="item.role_Name" :value="item.role_ID" /> </el-select>
                                </el-form-item>
                            </el-form>
                            <div slot="footer"
                                 class="dialog-footer">
                                <el-button @@click="dialogFormVisible = false">取 消</el-button>
                                <el-button type="primary"
                                           @@click="handleSet">确 定</el-button>
                            </div>
                        </el-dialog>
                    </template>
                </el-table-column>
            </el-table>
        </template>
        <div class="block">
            <el-pagination @@size-change="handleSizeChange"
                           @@current-change="handleCurrentChange"
                           :current-page="currentPage"
                           :page-sizes="[5, 10, 20, 30]"
                           :page-size="pagesize"
                           layout="total, sizes, prev, pager, next, jumper"
                           :total="tableData.length">
            </el-pagination>
        </div>
    </div>
    <script>
        var vm = new Vue({
            el: "div",
            data: {
                tableData: [],
                currentPage: 1,
                pagesize: 5,
                total: null,
                dialogFormVisible: false,//弹出层默认为关闭
                staff_ID: "",
                //弹出层中的表单
                form: {
                    staff_CODE: "",
                    staff_NAME: "",
                    role_ID: "",
                    
                },
                tableData1:[],
                formLabelWidth: '50px'
            },
            methods: {
                load() {
                    
                    axios.get("/User/Uases",).then(res => {
                        this.tableData = res.data;
                        this.total = res.data.length
                       
                    }),
                    axios.get("/User/Roles",).then(res => {
                        this.tableData1 = res.data;
                        console.log(this.tableData1)
                    })
                },
                
                handleSizeChange: function (val) {
                    this.pagesize = val
                    console.log(`每页 ${val} 条`);
                },
                handleCurrentChange: function (val) {
                    this.currentPage = val;
                    console.log(`当前页: ${val}`);
                },
                handleClick(row) {
                    console.log(row);
                },

                handleEdit(index, row) {
                    this.dialogFormVisible = true //开启弹出层
                    //对弹出层中的表单赋值 
                    
                    this.form.staff_CODE = row.staff_CODE
                    this.form.staff_NAME = row.staff_NAME
                    this.form.role_ID = row.role_ID
                    this.staff_ID =row.staff_ID
                    
                },
                handleSet() {
                    var params = {
                        role_ID: this.form.role_ID,
                        staff_ID: this.staff_ID
                    }
                    axios.post('/User/uPersonnel', params).then(
                        res => {
                            if (res.data>0) {
                                this.$message("修改成功！")
                            }
                            else {
                                this.$message("修改失败！")
                            }
                        }
                    )
                }
            },
            created() {
                this.load()
       
            }
        })
    </script>
</body>
</html>